package com.panshi.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.panshi.service.DetailService;
import com.panshi.service.ZxService;
import com.panshi.vo.ArticleOkVO;
import com.panshi.vo.CollectVO;
import com.panshi.vo.TitleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("zx")
public class ZxController {

    @Autowired
    ZxService zxService;

    @Autowired
    DetailService detailService;

    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/title")
    @ResponseBody
    public List<TitleVO> listTitleVOs() throws JsonProcessingException {
        return zxService.listTitleVOs();
    }

    //收藏文章
    @CrossOrigin(origins = "*", maxAge = 3600)
    @PostMapping("/collect/{collect}")
    @ResponseBody
    public Boolean listRecommendArticleOkVOs(@PathVariable(value = "collect") CollectVO collectVO) {
        return zxService.insertCollect(collectVO);
    }

    //资讯 加载更多
    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/load/{type}/{page}")
    @ResponseBody
    public List<ArticleOkVO> listArticleOkVOs(@PathVariable(value = "type") Integer type, @PathVariable(value = "page") Integer page) throws JsonProcessingException {
        return zxService.listSortLoadArticleOkVOs(type, page, -1);
    }

    //加载相关推荐
    @CrossOrigin(origins = "*", maxAge = 3600)
    @PostMapping("/recommend/{page}/{sort}")
    @ResponseBody
    public List<ArticleOkVO> listRecommendArticleOkVOs(@PathVariable(value = "page") String page, @PathVariable(value = "sort") String sort) {
        return zxService.listRecommendArticleOkVOs(page, sort);
    }

    //查询相关推荐页数
    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/page/{sort}")
    @ResponseBody
    public int countRecommendPage(@PathVariable(value = "sort") Integer sort) throws JsonProcessingException {
        return zxService.countRecommendPage(sort);
    }

    //其他看点
    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/other")
    @ResponseBody
    public List<ArticleOkVO> listOtherArticleOkVOs() {
        return zxService.listOtherArticleOkVOs();
    }

    //分类的相关推荐
    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/sort/recommend/{id}")
    @ResponseBody
    public List<ArticleOkVO> listRelatedRecommendArticleOkVOs(@PathVariable(value = "id") Integer id) {
        return zxService.listRelatedRecommendArticleOkVOs(id);
    }

    //资讯页 大家都在看
    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/sort/allwatch")
    @ResponseBody
    public List<ArticleOkVO> listAllWatchArticleOkVOs() {
        return zxService.listAllWatchArticleOkVOs();
    }    //大家都在看

    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/hot/{page}")
    @ResponseBody
    public List<ArticleOkVO> listHotArticleOkVOs(@PathVariable(value = "page") Integer page) throws JsonProcessingException {
        return zxService.listHotArticleOkVOs(page, -1);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/new/{page}")
    @ResponseBody
    public List<ArticleOkVO> listNewArticleOkVOs(@PathVariable(value = "page") Integer page) throws JsonProcessingException {
        return zxService.listNewArticleOkVOs(page, -1);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/sort/load/{type}/{page}/{sort}")
    @ResponseBody
    public List<ArticleOkVO> listSortLoadArticleOkVOs(@PathVariable(value = "type") Integer type, @PathVariable(value = "page") Integer page, @PathVariable(value = "sort") Integer sort) throws JsonProcessingException {
        return zxService.listSortLoadArticleOkVOs(type, page, sort);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/sort/hot/{page}/{sort}")
    @ResponseBody
    public List<ArticleOkVO> listSortHotArticleOkVOs(@PathVariable(value = "page") Integer page, @PathVariable(value = "sort") Integer sort) throws JsonProcessingException {
        return zxService.listHotArticleOkVOs(page, sort);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/sort/new/{page}/{sort}")
    @ResponseBody
    public List<ArticleOkVO> listSortNewArticleOkVOs(@PathVariable(value = "page") Integer page, @PathVariable(value = "sort") Integer sort) throws JsonProcessingException {
        return zxService.listNewArticleOkVOs(page, sort);
    }

    //查询资讯页数
    @CrossOrigin(origins = "*", maxAge = 3600)
    @GetMapping("/page")
    @ResponseBody
    public int countRecommendPage() {
        return zxService.countNewsPage();
    }

}
